package ch.hoth.java.joocal.actions;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.custom.CTabFolder;

import ch.hoth.java.joocal.Calendar;
import ch.hoth.java.joocal.CalendarController;
import ch.hoth.java.joocal.ui.CalendarWidget;

public class CalendarAction extends Action {
	
	private CalendarController controller;
	private CTabFolder folder;

	public CalendarAction(String name, CalendarController controller){
		super(name);
		this.controller = controller;
		
		try{ 
			setImageDescriptor(ImageDescriptor.createFromURL(new URL("file:img/"+name+".gif")));
		}
		catch (MalformedURLException e){
			e.printStackTrace();
		}
	}

	public void setFolder(CTabFolder folder) {
		this.folder = folder;
	}
	
	protected Calendar getCalendar(){
		return ((CalendarWidget) folder.getSelection()).getCalendar(); 
	}
	
	protected CalendarController getController(){
		return controller;
	}
}
